//
//  UIButton+Extension.swift
//  WeoboWithSteveLi
//
//  Created by SteveLi on 2017/9/18.
//  Copyright © 2017年 李军桦. All rights reserved.
//

import UIKit
extension UIButton{
    /// 遍历构造函数
    ///
    /// - parameter imageName:     图形名称
    /// - parameter backImageName: 背景图形名称
    ///
    /// - returns: UIButton
    convenience init(imageName: String ,backImageName: String) {
    self.init()
        
        setImage(UIImage.init(named: imageName), for: .normal)
        setImage(UIImage.init(named: imageName + "_hightlighted"), for: .highlighted)
        setBackgroundImage(UIImage.init(named: backImageName), for: .normal)
        setBackgroundImage(UIImage.init(named:backImageName + "_hightlighted"), for: .highlighted)
        //会根据背景图片的大小调整尺寸
        sizeToFit()
    
    }
    //TODO: - 修改参数名
    /// 遍历构造函数
    ///
    /// - parameter title:     title
    /// - parameter color:     color
    /// - parameter backImageName: 背景图片
    ///
    /// - returns: UIButton
    convenience init(title:String,color:UIColor,backImageName:String) {
        self.init()
        setTitle(title, for: .normal)
        setTitleColor(color, for: .normal)
        setBackgroundImage(UIImage.init(named: backImageName), for: .normal)
        sizeToFit()
    }
    
    /// 遍历构造函数
    ///
    /// - parameter title:     title
    /// - parameter fontSize:     字体大小
    /// - parameter color:     color
    /// - parameter imageName: imageName
    ///
    /// - returns: UIButton
    convenience init(title:String,fontSize:CGFloat ,color:UIColor,imageName:String) {
        self.init()
        setTitle(title, for: .normal)
        setTitleColor(color, for: .normal)
        setImage(UIImage.init(named: imageName), for: .normal)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        sizeToFit()
    }
    
}
